package model

import (
	"database/sql"
	"time"
)

func (User) TableName() string {
	return "user"
}

// User table user struct
type User struct {
	Model
	Username string         `gorm:"unique;not null"`
	Email    string         `gorm:"unique;not null"`
	Phone    sql.NullString `gorm:"index;size:20;not null;default:''"`
	Role     sql.NullInt16  `gorm:"size:4;not null;default:100"`
	Password string         `gorm:"size:40;not null"`
	Salt     string         `gorm:"size:40;not null"`
	AppName  string         `gorm:"unique;not null;comment:third party app name"`
	AppKey   string         `gorm:"unique;not null;comment:third party app key"`
	Comment  string         `gorm:"not null;default:''"`
	Enable   sql.NullInt16  `gorm:"size:4;not null;default:0"` // default 0: enable 1: disable
}

type RequestLogin struct {
	Username     string `json:"username" form:"username" validate:"required" verify_msg:"username required" example:"superadmin"` // Username
	Password     string `json:"password" form:"password" validate:"required" verify_msg:"password required" example:"superadmin"` // Password
	CaptchaId    string `json:"captcha_id" form:"captcha_id" validate:"required" verify_msg:"captchaId required"`                 // Captcha Id
	CaptchaValue string `json:"captcha_value" form:"captcha_value" validate:"required" verify_msg:"captchaValue required"`        // Captcha Value
}

type RequestUsers struct {
	Enable   int    `json:"enable" form:"enable"`                                                           // Enable
	Username string `json:"username" form:"username"`                                                       // Username
	Email    string `json:"email" form:"email"`                                                             // Email
	Page     int    `json:"page" form:"page" validate:"required" verify_msg:"page required"`                // Page
	PageSize int    `json:"page_size" form:"page_size" validate:"required" verify_msg:"page_size required"` //PageSize
}

type RequestReToken struct {
	Token        string `json:"token" form:"token" validate:"required" verify_msg:"token required"`                         // Token
	RefreshToken string `json:"refresh_token" form:"refresh_token" validate:"required" verify_msg:"refresh_token required"` // RefreshToken
}

type ResponseUsersDataData struct {
	Id        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"deleted_at"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Phone     string    `json:"phone"`
	Role      int       `json:"role"`
	AppName   string    `json:"app_name"`
	AppKey    string    `json:"app_key"`
	Comment   string    `json:"comment"`
	Enable    int       `json:"enable"`
}

type ResponseUsersData struct {
	Page     int                     `json:"page"`
	PageSize int                     `json:"page_size"`
	Total    int64                   `json:"total"`
	Data     []ResponseUsersDataData `json:"data"`
}

type ResponseUsers struct {
	Code int               `json:"code"`
	Data ResponseUsersData `json:"data"`
	Msg  string            `json:"msg"`
}
